package wechat.rcv.mock.service;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.uniquesoft.gwt.server.service.common.HttpRequestThreadLocal;

import edu.fudan.langlab.domain.organization.Party;
import edu.fudan.langlab.domain.security.ISystemUserService;
import edu.fudan.langlab.domain.security.User;
import edu.fudan.langlab.domain.security.impl.UserImpl;
import edu.fudan.mylang.pf.BaseService;
import edu.fudan.mylang.pf.IObjectFactory;

@Service("wechat.rcv.login.service.login.ISecurityService")
public class SystemUserServiceImpl extends BaseService implements
		ISystemUserService {
//	@Autowired
//	private IObjectFactory objectFactory;

	public User getCurrentUser() {
//		User _xblockexpression = null;
//		{
//			HttpServletRequest req = HttpRequestThreadLocal.get();
//			HttpSession _session = req.getSession();
//			Object _attribute = _session.getAttribute("__userid__");
//			Long userid = ((Long) _attribute);
//			if (userid != null) {
//				User _get = this.objectFactory.<User> get(User.class, userid);
//				_xblockexpression = (_get);
//			}
//		}
		User _xblockexpression = new UserImpl();
		_xblockexpression.setId(11l);
		return _xblockexpression;
	}

	public void setCurrentUser(final User user) {
		HttpServletRequest req = HttpRequestThreadLocal.get();
		HttpSession _session = req.getSession();
		Long _id = user.getId();
		_session.setAttribute("__userid__", _id);
	}

	public Party getCurrentUserAsParty() {
//		Party _xblockexpression = null;
//		{
//			HttpServletRequest req = HttpRequestThreadLocal.get();
//			HttpSession _session = req.getSession();
//			Object _attribute = _session.getAttribute("__userid__");
//			Long userid = ((Long) _attribute);
//			User user = this.objectFactory.<User> get(User.class, userid);
//			Party _switchResult = null;
//			boolean _matched = false;
//			if (!_matched) {
//				if (user instanceof EmployeeUser) {
//					final EmployeeUser _rCEmployeeUser = (EmployeeUser) user;
//					_matched = true;
//					Employee _employee = _rCEmployeeUser.getEmployee();
//					_switchResult = _employee;
//				}
//			}
//			_xblockexpression = (_switchResult);
//		}
//		return _xblockexpression;
		return null;
	}

	@Override
	public void logout() {
		HttpServletRequest req = HttpRequestThreadLocal.get();
		HttpSession _session = req.getSession();
		_session.removeAttribute("__userid__");

	}

}
